package com.wframe.project.former.web.sysman;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.hibernate.HibernateException;

import com.frame.database.JdataBean;
import com.frame.pageform.ClientException;
import com.frame.pageform.PageForm;
import com.wframe.project.former.dataservices.sysman.SysmanService;

public class SysmanPage extends PageForm{

	private JdataBean bean;
	private List<JdataBean> list;
	
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		bean=SysmanService.getIntance().getSyspro();
		return "/webadmin/sysman/SysproSet.jsp";
	}
	
	public String saveSyspro() throws Exception{
		SysmanService.getIntance().saveSysproVal(bean);
		getJsonObject().put("state", "ok");
		return getJsonObject().toString();
	}
	
	/**
	 * 控销区域管理
	 * @return
	 * @throws Exception 
	 */
	public String areatradList() throws Exception{
		setList(SysmanService.getIntance().queryAreatrad());
		return "/webadmin/sysman/areatradList.jsp";
	}
	/**
	 * 控销区域管理
	 * @return
	 * @throws Exception 
	 */
	public String areatradshow() throws Exception{
		if(bean!=null && StringUtils.isNotBlank(bean.getString("id")))
			bean=SysmanService.getIntance().getAreatrad(bean.getString("id"));
		return "/webadmin/sysman/areatradEdit.jsp";
	}
	/**
	 * 控销区域管理
	 * @return
	 * @throws Exception 
	 */
	public String areatradSave() throws Exception{
		String p=bean.getString("province");if(p==null || "null".equals(p))p="";
		String c=bean.getString("city");if(c==null || "null".equals(c))c="";
		String d=bean.getString("area");if(d==null || "null".equals(d))d="";
		String name=p+c+d;
		if(StringUtils.isBlank(name))throw new ClientException("请选择区域");
		SysmanService.getIntance().saveAreatrad(bean);
		getJsonObject().getJsonPage().showOkMsg("保存成功");
		getJsonObject().getJsonPage().closeWin("ok");
		return getJsonObject().toString();
	}
	/**
	 * 控销区域管理
	 * @return
	 * @throws Exception 
	 * @throws HibernateException 
	 */
	public String areatradDel() throws HibernateException, Exception{
		SysmanService.getIntance().delAreatrad(bean.getString("id"));
		return getJsonObject().toString();
	}

	public JdataBean getBean() {
		return bean;
	}

	public void setBean(JdataBean bean) {
		this.bean = bean;
	}

	public List<JdataBean> getList() {
		return list;
	}

	public void setList(List<JdataBean> list) {
		this.list = list;
	}

	
}
